<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="">
<head>
    <meta charset="utf-8">
    <title>控制后台</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" th:href="@{/pear/component/pear/css/pear.css}"/>
    <link rel="stylesheet" th:href="@{/pear/admin/css/other/console1.css}"/>
</head>
<body class="pear-container">
<div class="layui-row layui-col-space10">
    <div class="layui-col-md12" style="height: 65px; margin-bottom: 35px">
        <div class="layui-card">
            <div class="layui-card-body">
                <div id="welcome-message" class="welcome-message" style="height: 100px"></div>
            </div>
        </div>
    </div>
</div>
<div>
    <div class="layui-row layui-col-space10" style="margin-top: 55px">
        <div class="layui-col-xs6 layui-col-md4">
            <div class="layui-card top-panel">
                <div class="layui-card-header">总访问量(UV)</div>
                <div class="layui-card-body">
                    <div class="layui-row layui-col-space5">
                        <div class="layui-col-xs8 layui-col-md8 top-panel-number" style="color: #28333E;"
                             id="ipVisitCount">
                        </div>
                        <div class="layui-col-xs4 layui-col-md4 top-panel-tips">
                            <svg xmlns="http://www.w3.org/2000/svg" class="icon" viewBox="0 0 1024 1024" width="200"
                                 height="200" x="1591462258798"
                                 p-id="942" version="1.1">
                                <path fill="#fcc66f"
                                      d="M 262.7 835 c -15.3 0 -28.1 -11.4 -29.8 -26.6 L 174.1 291 c -0.6 -5.1 1 -10.2 4.5 -14 s 8.3 -6 13.4 -6 h 640 c 5.1 0 10 2.2 13.4 6 s 5 8.9 4.5 14 l -58.8 517.4 c -1.7 15.2 -14.5 26.6 -29.8 26.6 H 262.7 Z"
                                      p-id="943"/>
                                <path fill="#ffd79c"
                                      d="M 802 289 l -58.8 517.4 c -0.7 6.1 -5.8 10.6 -11.9 10.6 h 30 c 6.1 0 11.2 -4.6 11.9 -10.6 L 832 289 h -30 Z"
                                      p-id="944"/>
                                <path fill="#f56e73"
                                      d="M 164 307 c -16.5 0 -30 -13.5 -30 -30 v -58 c 0 -16.5 13.5 -30 30 -30 h 696 c 16.5 0 30 13.5 30 30 v 58 c 0 16.5 -13.5 30 -30 30 H 164 Z"
                                      p-id="945"/>
                                <path fill="#ffa1a8"
                                      d="M 860 207 h -30 c 6.6 0 12 5.4 12 12 v 58 c 0 6.6 -5.4 12 -12 12 h 30 c 6.6 0 12 -5.4 12 -12 v -58 c 0 -6.6 -5.4 -12 -12 -12 Z"
                                      p-id="946"/>
                                <path fill="#65c8ff"
                                      d="M 190.9 651.5 c -31.4 0 -56.9 -25.5 -56.9 -56.9 V 219 c 0 -16.5 13.5 -30 30 -30 h 466.2 c 9.9 0 18 8.1 18 18 v 301.1 c 0 34.7 -28.2 62.9 -62.9 62.9 s -62.9 -28.2 -62.9 -62.9 V 393.5 c 0 -23.2 -18.8 -42 -42 -42 s -42 18.8 -42 42 v 68.1 c 0 29.4 -23.9 53.4 -53.4 53.4 s -53.4 -23.9 -53.4 -53.4 v -68.1 c 0 -23.2 -18.8 -42 -42 -42 s -42 18.8 -42 42 v 201.1 c 0.1 31.4 -25.4 56.9 -56.7 56.9 Z"
                                      p-id="947"/>
                                <path fill="#b3eaff"
                                      d="M 277.8 321.5 c -33.1 0 -60 26.9 -60 60 v 201.1 c 0 21.5 -17.4 38.9 -38.9 38.9 c -7.7 0 -14.8 -2.2 -20.8 -6.1 c 6.9 10.9 19 18.1 32.8 18.1 c 21.5 0 38.9 -17.4 38.9 -38.9 V 393.5 c 0 -33.1 26.9 -60 60 -60 c 13.5 0 25.9 4.5 36 12 c -11 -14.5 -28.4 -24 -48 -24 Z M 618.3 207 v 289.1 c 0 24.8 -20.1 44.9 -44.9 44.9 c -9.3 0 -18 -2.8 -25.2 -7.7 c 8.1 11.9 21.7 19.7 37.2 19.7 c 24.8 0 44.9 -20.1 44.9 -44.9 V 207 h -12 Z M 468.5 321.5 c -33.1 0 -60 26.9 -60 60 v 68.1 c 0 19.5 -15.8 35.4 -35.4 35.4 c -6.7 0 -12.9 -1.9 -18.3 -5.1 c 6.2 10.2 17.4 17.1 30.3 17.1 c 19.5 0 35.4 -15.8 35.4 -35.4 v -68.1 c 0 -33.1 26.9 -60 60 -60 c 13.5 0 25.9 4.5 36 12 c -11 -14.5 -28.4 -24 -48 -24 Z"
                                      p-id="948"/>
                                <path fill="#453b56" d="M 698 729.4 m -18 0 a 18 18 0 1 0 36 0 a 18 18 0 1 0 -36 0 Z"
                                      p-id="949"/>
                                <path fill="#453b56"
                                      d="M 860 171 H 632.5 v 0.1 c -0.7 0 -1.5 -0.1 -2.2 -0.1 H 164 c -26.5 0 -48 21.5 -48 48 v 375.6 c 0 41.3 33.6 74.9 74.9 74.9 c 2.7 0 5.4 -0.2 8.1 -0.5 l 16 141.4 c 2.8 24.3 23.3 42.6 47.7 42.6 h 498.6 c 24.4 0 44.9 -18.3 47.7 -42.6 l 55.2 -485.6 c 24.5 -2.1 43.8 -22.7 43.8 -47.8 v -58 c 0 -26.5 -21.5 -48 -48 -48 Z M 190.9 633.5 c -21.5 0 -38.9 -17.4 -38.9 -38.9 V 219 c 0 -6.6 5.4 -12 12 -12 h 466.3 v 301.1 c 0 24.8 -20.1 44.9 -44.9 44.9 c -24.8 0 -44.9 -20.1 -44.9 -44.9 V 393.5 c 0 -33.1 -26.9 -60 -60 -60 s -60 26.9 -60 60 v 68.1 c 0 19.5 -15.8 35.4 -35.4 35.4 c -19.5 0 -35.4 -15.8 -35.4 -35.4 v -68.1 c 0 -33.1 -26.9 -60 -60 -60 s -60 26.9 -60 60 v 201.1 c 0.1 21.5 -17.4 38.9 -38.8 38.9 Z m 582.3 172.9 c -0.7 6.1 -5.8 10.6 -11.9 10.6 H 262.7 c -6.1 0 -11.2 -4.6 -11.9 -10.6 l -6.7 -59 h 396.6 c 9.9 0 18 -8.1 18 -18 s -8.1 -18 -18 -18 H 240 l -6.3 -55.4 c 19.3 -13.6 32.1 -36 32.1 -61.3 V 393.5 c 0 -13.2 10.8 -24 24 -24 s 24 10.8 24 24 v 68.1 c 0 39.4 32 71.4 71.4 71.4 s 71.4 -32 71.4 -71.4 v -68.1 c 0 -13.2 10.8 -24 24 -24 s 24 10.8 24 24 v 114.6 c 0 44.6 36.3 80.9 80.9 80.9 c 44.6 0 80.9 -36.3 80.9 -80.9 V 325 h 161.7 l -54.9 481.4 Z M 872 277 c 0 6.6 -5.4 12 -12 12 H 666.3 v -82 H 860 c 6.6 0 12 5.4 12 12 v 58 Z"
                                      p-id="950"/>
                            </svg>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-col-xs6 layui-col-md4">
            <div class="layui-card top-panel">
                <div class="layui-card-header">栏目总浏览量(PV)</div>
                <div class="layui-card-body">
                    <div class="layui-row layui-col-space5">
                        <div class="layui-col-xs8 layui-col-md8 top-panel-number" style="color: #28333E;"
                             id="channelValue">

                        </div>
                        <div class="layui-col-xs4 layui-col-md4  top-panel-tips">
                            <svg x="1591462464512" class="icon" viewBox="0 0 1024 1024" version="1.1"
                                 xmlns="http://www.w3.org/2000/svg"
                                 p-id="3311" width="200" height="200">
                                <path d="M750.4 216.5h-130v-15.3c0-32.9-26.8-59.7-59.7-59.7h-97.3c-32.9 0-59.7 26.8-59.7 59.7v15.3h-130c-30.7 0-55.6 25-55.6 55.6v72.4c0 9.9 8.1 18 18 18h31.5v478c0 23.2 18.8 42 42 42h405c23.2 0 42-18.8 42-42v-478H788c9.9 0 18-8.1 18-18v-72.4c0-30.6-25-55.6-55.6-55.6z"
                                      fill="#FCC66F" p-id="3312"></path>
                                <path d="M708.5 344.5v496c0 13.3-10.7 24-24 24h30c13.3 0 24-10.7 24-24v-496h-30z"
                                      fill="#FFD79C" p-id="3313"></path>
                                <path d="M309.5 882.5c-23.2 0-42-18.8-42-42V596c0-9.9 8.1-18 18-18h36.8c30.2 0 54.8 24.6 54.8 54.8v231.7c0 9.9-8.1 18-18 18h-49.6zM664.9 882.5c-9.9 0-18-8.1-18-18V632.8c0-30.2 24.6-54.8 54.8-54.8h36.8c9.9 0 18 8.1 18 18v244.5c0 23.2-18.8 42-42 42h-49.6z"
                                      fill="#F56E73" p-id="3314"></path>
                                <path d="M708.5 596v244.5c0 13.3-10.7 24-24 24h30c13.3 0 24-10.7 24-24V596h-30z"
                                      fill="#FFA1A8" p-id="3315"></path>
                                <path d="M475.2 882.5c-9.9 0-18-8.1-18-18V632.8c0-30.2 24.6-54.8 54.8-54.8 30.2 0 54.8 24.6 54.8 54.8v231.7c0 9.9-8.1 18-18 18h-73.6z"
                                      fill="#F56E73" p-id="3316"></path>
                                <path d="M560.7 159.5h-18c23 0 41.7 18.7 41.7 41.7V221h18v-19.8c-0.1-23-18.7-41.7-41.7-41.7zM750.4 234.5h-30c20.8 0 37.6 16.8 37.6 37.6v72.4h30v-72.4c0-20.8-16.8-37.6-37.6-37.6z"
                                      fill="#FFD79C" p-id="3317"></path>
                                <path d="M750.4 198.5H638.2c-1.4-41.6-35.6-75-77.5-75h-97.3c-41.9 0-76.1 33.4-77.5 75H273.6c-40.6 0-73.6 33-73.6 73.6v72.4c0 19.9 16.1 36 36 36h13.5v460c0 33.1 26.9 60 60 60H714.7c33.1 0 60-26.9 60-60v-460H788c19.9 0 36-16.1 36-36v-72.4c0-40.6-33-73.6-73.6-73.6z m-287.1-39h97.3c22.1 0 40.2 17.2 41.5 39H421.8c1.4-21.8 19.4-39 41.5-39z m-104.2 705h-49.6c-13.3 0-24-10.7-24-24V596h36.8c20.3 0 36.8 16.5 36.8 36.8v231.7z m189.7 0h-73.6V632.8c0-20.3 16.5-36.8 36.8-36.8 20.3 0 36.8 16.5 36.8 36.8v231.7z m189.7-24c0 13.3-10.7 24-24 24h-49.6V632.8c0-20.3 16.5-36.8 36.8-36.8h36.8v244.5z m0-280.5h-36.8c-40.1 0-72.8 32.6-72.8 72.8v231.7h-44.2V632.8c0-40.1-32.6-72.8-72.8-72.8-40.1 0-72.8 32.6-72.8 72.8v231.7h-44.2V632.8c0-40.1-32.6-72.8-72.8-72.8h-36.8v-74.5h279c9.9 0 18-8.1 18-18s-8.1-18-18-18h-279v-69h453V560zM788 344.5H236v-72.4c0-20.8 16.8-37.6 37.6-37.6h476.8c20.8 0 37.6 16.8 37.6 37.6v72.4z"
                                      fill="#453B56" p-id="3318"></path>
                                <path d="M621.8 467.5m-18 0a18 18 0 1 0 36 0 18 18 0 1 0-36 0Z" fill="#453B56"
                                      p-id="3319"></path>
                            </svg>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-col-xs6 layui-col-md4">
            <div class="layui-card top-panel">
                <div class="layui-card-header">文章总浏览量(PV)</div>
                <div class="layui-card-body">
                    <div class="layui-row layui-col-space5">
                        <div class="layui-col-xs8 layui-col-md8 top-panel-number" style="color: #28333E;"
                             id="infoValue">
                        </div>
                        <div class="layui-col-xs4 layui-col-md4 top-panel-tips">
                            <svg x="1591462491887" class="icon" viewBox="0 0 1024 1024" version="1.1"
                                 xmlns="http://www.w3.org/2000/svg"
                                 p-id="3449" width="200" height="200">
                                <path d="M363.2 807c-9.9 0-18-8.1-18-18v-75.5c0-9.9 8.1-18 18-18h108.5c9.9 0 18 8.1 18 18V789c0 9.9-8.1 18-18 18H363.2z"
                                      fill="#F56E73" p-id="3450"></path>
                                <path d="M441.7 713.5h30V789h-30z" fill="#FFA1A8" p-id="3451"></path>
                                <path d="M259.6 398c-9.9 0-18-8.1-18-18V178.6c0-23.8 19.3-43.1 43.1-43.1s43.1 19.3 43.1 43.1V380c0 9.9-8.1 18-18 18h-50.2zM525.1 398c-9.9 0-18-8.1-18-18V178.6c0-23.8 19.3-43.1 43.1-43.1s43.1 19.3 43.1 43.1V380c0 9.9-8.1 18-18 18h-50.2z"
                                      fill="#65C8FF" p-id="3452"></path>
                                <path d="M550.2 153.5c-3.2 0-6.2 0.7-9 1.7 9.4 3.6 16.1 12.7 16.1 23.4V380h18V178.6c0.1-13.9-11.2-25.1-25.1-25.1z"
                                      fill="#97DCFF" p-id="3453"></path>
                                <path d="M686 330.5H149c-9.9 0-18 8.1-18 18v63c0 9.9 8.1 18 18 18h33.2l45 225c8.7 43.4 47.1 75 91.4 75h197.6c44.3 0 82.7-31.5 91.4-75l45-225H686c9.9 0 18-8.1 18-18v-63c0-9.9-8.1-18-18-18z"
                                      fill="#FCC66F" p-id="3454"></path>
                                <path d="M608 411.5L560.1 651c-7 35.2-37.9 60.5-73.8 60.5h30c35.9 0 66.7-25.3 73.8-60.5L638 411.5h-30zM656 348.5h30v63h-30z"
                                      fill="#FFD79C" p-id="3455"></path>
                                <path d="M474.2 543.5m-18 0a18 18 0 1 0 36 0 18 18 0 1 0-36 0Z" fill="#453B56"
                                      p-id="3456"></path>
                                <path d="M416.9 525.5h-125c-9.9 0-18 8.1-18 18s8.1 18 18 18h125c9.9 0 18-8.1 18-18s-8.1-18-18-18zM893 543.5h-33.4c-65.2 0-118.2 53-118.2 118.2v19.6c0 9.9 8.1 18 18 18s18-8.1 18-18v-19.6c0-45.3 36.9-82.2 82.2-82.2H893c9.9 0 18-8.1 18-18s-8-18-18-18zM772.2 744.2c7-7 7-18.4 0-25.5-7-7-18.4-7-25.5 0s-7 18.4 0 25.5 18.4 7.1 25.5 0z"
                                      fill="#453B56" p-id="3457"></path>
                                <path d="M759.5 761.6c-9.9 0-18 8.1-18 18v11.6c0 43.7-35.6 79.3-79.3 79.3H487.3c-26.4 0-48.3-19.9-51.4-45.5h35.8c19.9 0 36-16.1 36-36v-41.5h8.6c52.8 0 98.7-37.6 109.1-89.4l42.1-210.6H686c19.9 0 36-16.1 36-36v-63c0-19.9-16.1-36-36-36h-74.6V178.6c0-33.7-27.4-61.1-61.1-61.1s-61.1 27.4-61.1 61.1v133.9H345.9V178.6c0-33.7-27.4-61.1-61.1-61.1s-61.1 27.4-61.1 61.1v133.9H149c-19.9 0-36 16.1-36 36v63c0 19.9 16.1 36 36 36h18.5l42.1 210.6c10.4 51.8 56.2 89.4 109.1 89.4h8.6V789c0 19.9 16.1 36 36 36h36.6c3.3 45.5 41.2 81.5 87.5 81.5h174.8c63.6 0 115.3-51.7 115.3-115.3v-11.6c0-10-8.1-18-18-18z m-234.4-583c0-13.9 11.2-25.1 25.1-25.1s25.1 11.2 25.1 25.1v133.9H525V178.6z m-265.5 0c0-13.9 11.2-25.1 25.1-25.1s25.1 11.2 25.1 25.1v133.9h-50.3V178.6zM149 411.5v-63h537v63H149z m169.7 300c-35.9 0-66.7-25.3-73.8-60.5l-40.7-203.5h426.6L590.1 651c-7 35.2-37.9 60.5-73.8 60.5H318.7z m44.5 77.5v-41.5h108.5V789H363.2z"
                                      fill="#453B56" p-id="3458"></path>
                            </svg>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </div>
    <div class="layui-row layui-col-space10">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body">
                    <div style="display: flex;align-items: center;justify-content: left">
                        <!-- 时间段选择按钮 -->
                        <div class="layui-btn-group" id="time-range-buttons-article">
                            <button class="layui-btn layui-btn-normal" onclick="filterArticles('default')">默认</button>
                            <button class="layui-btn layui-btn-normal" onclick="filterArticles('day')">日</button>
                            <button class="layui-btn layui-btn-normal" onclick="filterArticles('week')">周</button>
                            <button class="layui-btn layui-btn-normal" onclick="filterArticles('month')">月</button>
                            <button class="layui-btn layui-btn-normal" onclick="filterArticles('year')">年</button>
                            <button class="layui-btn layui-btn-normal" onclick="filterArticles('custom')">自定义
                            </button>
                        </div>
                        <!-- 隐藏的日期时间范围选择器 -->
                        <div class="layui-inline" style="display: none;" id="custom-date-range-article">
                            <label class="layui-form-label">日期范围</label>
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input" id="ID-laydate-range-datetime-article"
                                       placeholder=" - ">
                            </div>
                        </div>
                    </div>
                    <table id="article-table" lay-filter="article-table"></table>
                </div>
            </div>
        </div>
    </div>

    <div class="layui-row layui-col-space10" style="margin-bottom: 30px">
        <div class="layui-col-md12">
            <div class="layui-card-header">
                <!-- 隐藏的导出链接 -->
                <a id="exportChannel" download="栏目数据.xlsx" style="display: none;"></a>

                <!-- 导出按钮 -->
                <button style="float: right" type="submit" class="layui-btn layui-btn-success layui-btn-sm"
                        onclick="triggerExport()">
                    <i class="layui-icon layui-icon-export"></i>
                    导出栏目数据
                </button>
            </div>
            <div class="layui-card">
                <div class="layui-card-body">
                    <div style="display: flex;align-items: center;justify-content: left">
                        <!-- 时间段选择按钮 -->
                        <div class="layui-btn-group" id="time-range-buttons-channel">
                            <button class="layui-btn layui-btn-normal" onclick="filterChannels('default')">默认</button>
                            <button class="layui-btn layui-btn-normal" onclick="filterChannels('day')">日</button>
                            <button class="layui-btn layui-btn-normal" onclick="filterChannels('week')">周</button>
                            <button class="layui-btn layui-btn-normal" onclick="filterChannels('month')">月</button>
                            <button class="layui-btn layui-btn-normal" onclick="filterChannels('year')">年</button>
                            <button class="layui-btn layui-btn-normal" onclick="filterChannels('custom')">自定义
                            </button>
                        </div>
                        <!-- 隐藏的日期时间范围选择器 -->
                        <div class="layui-inline" style="display: none;" id="custom-date-range-channel">
                            <label class="layui-form-label">日期范围</label>
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input" id="ID-laydate-range-datetime-channel"
                                       placeholder=" - ">
                            </div>
                        </div>
                    </div>
                    <table id="channel-table" lay-filter="channel-table"></table>
                </div>
            </div>
        </div>
    </div>
    <div class="copyright-info" id="copyright-info"></div>
</div>

<script th:src="@{/pear/component/layui/layui.js}"></script>
<script th:src="@{/pear/component/pear/pear.js}"></script>
<script th:inline="javascript">
    let baseURL = /*[[@{/}]]*/ '';
    document.addEventListener('DOMContentLoaded', function () {

        // 检查外部资源是否加载成功
        const scripts = document.querySelectorAll('script');
        scripts.forEach(script => {
            if (script.src && !script.complete) {
                console.warn(`Script not loaded: ${script.src}`);
            }
        });

        layui.use(['table', 'layer', 'count', 'laydate'], function () {
            const count = layui.count
            let table = layui.table;
            let laydate = layui.laydate;
            let articleDate = null; // 文章日期为空
            let channelDate = null; // 栏目日期为空

            // 初始化文章表格
            table.render({
                elem: '#article-table',
                url: baseURL + 'cms/infoArticle/countArticle', // API 地址
                where: {
                    date: articleDate,
                },
                parseData: function (res) { // 解析后端返回的数据
                    return {
                        "code": res.code, // 状态码
                        "msg": res.msg, // 返回消息
                        "data": res.data // 数据列表
                    };
                },
                cols: [
                    [
                        {type: 'checkbox'},
                        {field: 'title', title: '文章标题', minWidth: 200},
                        {field: 'count', title: '文章访问量', minWidth: 200},
                    ]
                ],
                response: {
                    statusCode: 1000
                }
            });

            // 初始化栏目表格
            table.render({
                elem: '#channel-table',
                url: baseURL + 'cms/channel/countChannel', // API 地址
                where: {
                    date: channelDate,
                },
                parseData: function (res) { // 解析后端返回的数据
                    return {
                        "code": res.code, // 状态码
                        "msg": res.msg, // 返回消息
                        "data": res.data // 数据列表
                    };
                },
                cols: [
                    [
                        {type: 'checkbox'},
                        {field: 'channelName', title: '栏目名称', minWidth: 200},
                        {field: 'count', title: '栏目访问量', minWidth: 200},
                    ]
                ],
                response: {
                    statusCode: 1000
                }
            });

            // 文章时间段筛选逻辑
            window.filterArticles = function (range) {
                let startDate, endDate;

                switch (range) {
                    case 'default':
                        // 默认显示所有数据
                        articleDate = null;
                        document.getElementById('custom-date-range-article').style.display = 'none';
                        break;
                    case 'day':
                        // 日数据
                        startDate = new Date();
                        startDate.setHours(0, 0, 0, 0); // 当天开始时间（午夜0点）
                        endDate = new Date();
                        endDate.setHours(23, 59, 59, 999); // 当天结束时间（接近午夜的最后一刻）
                        articleDate = formatDate(startDate) + " - " + formatDate(endDate);
                        document.getElementById('custom-date-range-article').style.display = 'none';
                        break;
                    case 'week':
                        // 周数据
                        startDate = new Date();
                        startDate.setDate(startDate.getDate() - 7);
                        startDate.setHours(0, 0, 0, 0); // 7天前开始时间
                        endDate = new Date();
                        endDate.setHours(23, 59, 59, 999); // 当天结束时间
                        articleDate = formatDate(startDate) + " - " + formatDate(endDate);
                        document.getElementById('custom-date-range-article').style.display = 'none';
                        break;
                    case 'month':
                        // 月数据
                        startDate = new Date();
                        startDate.setDate(1);
                        startDate.setHours(0, 0, 0, 0); // 当月第一天开始时间
                        endDate = new Date();
                        endDate.setMonth(endDate.getMonth() + 1, 0);
                        endDate.setHours(23, 59, 59, 999); // 当月最后一天结束时间
                        articleDate = formatDate(startDate) + " - " + formatDate(endDate);
                        document.getElementById('custom-date-range-article').style.display = 'none';
                        break;
                    case 'year':
                        // 年数据
                        startDate = new Date();
                        startDate.setMonth(0, 1);
                        startDate.setHours(0, 0, 0, 0); // 当年第一天开始时间
                        endDate = new Date();
                        endDate.setMonth(11, 31);
                        endDate.setHours(23, 59, 59, 999); // 当年最后一天结束时间
                        articleDate = formatDate(startDate) + " - " + formatDate(endDate);
                        document.getElementById('custom-date-range-article').style.display = 'none';
                        break;
                    case 'custom':
                        // 自定义时间段
                        document.getElementById('custom-date-range-article').style.display = 'inline-block';
                        laydate.render({
                            elem: '#ID-laydate-range-datetime-article',
                            type: 'datetime',
                            range: true,
                            format: 'yyyy-MM-dd HH:mm:ss',
                            done: function (value) {
                                articleDate = value;
                                document.getElementById('custom-date-range-article').style.display = 'none';
                                reloadArticleTable();
                            }
                        });
                        return; // 防止重新加载表格
                }

                // 重新加载文章表格
                reloadArticleTable();
            };

            // 栏目时间段筛选逻辑
            window.filterChannels = function (range) {
                let startDate, endDate;

                switch (range) {
                    case 'default':
                        // 默认显示所有数据
                        channelDate = null;
                        document.getElementById('custom-date-range-channel').style.display = 'none';
                        break;
                    case 'day':
                        // 日数据
                        startDate = new Date();
                        startDate.setHours(0, 0, 0, 0); // 当天开始时间（午夜0点）
                        endDate = new Date();
                        endDate.setHours(23, 59, 59, 999); // 当天结束时间（接近午夜的最后一刻）
                        channelDate = formatDate(startDate) + " - " + formatDate(endDate);
                        document.getElementById('custom-date-range-channel').style.display = 'none';
                        break;
                    case 'week':
                        // 周数据
                        startDate = new Date();
                        startDate.setDate(startDate.getDate() - 7);
                        startDate.setHours(0, 0, 0, 0); // 7天前开始时间
                        endDate = new Date();
                        endDate.setHours(23, 59, 59, 999); // 当天结束时间
                        channelDate = formatDate(startDate) + " - " + formatDate(endDate);
                        document.getElementById('custom-date-range-channel').style.display = 'none';
                        break;
                    case 'month':
                        // 月数据
                        startDate = new Date();
                        startDate.setDate(1);
                        startDate.setHours(0, 0, 0, 0); // 当月第一天开始时间
                        endDate = new Date();
                        endDate.setMonth(endDate.getMonth() + 1, 0);
                        endDate.setHours(23, 59, 59, 999); // 当月最后一天结束时间
                        channelDate = formatDate(startDate) + " - " + formatDate(endDate);
                        document.getElementById('custom-date-range-channel').style.display = 'none';
                        break;
                    case 'year':
                        // 年数据
                        startDate = new Date();
                        startDate.setMonth(0, 1);
                        startDate.setHours(0, 0, 0, 0); // 当年第一天开始时间
                        endDate = new Date();
                        endDate.setMonth(11, 31);
                        endDate.setHours(23, 59, 59, 999); // 当年最后一天结束时间
                        channelDate = formatDate(startDate) + " - " + formatDate(endDate);
                        document.getElementById('custom-date-range-channel').style.display = 'none';
                        break;
                    case 'custom':
                        // 自定义时间段
                        document.getElementById('custom-date-range-channel').style.display = 'inline-block';
                        laydate.render({
                            elem: '#ID-laydate-range-datetime-channel',
                            type: 'datetime',
                            range: true,
                            format: 'yyyy-MM-dd HH:mm:ss',
                            done: function (value) {
                                channelDate = value;
                                document.getElementById('custom-date-range-channel').style.display = 'none';
                                reloadChannelTable();
                            }
                        });
                        return; // 防止重新加载表格
                }

                // 重新加载栏目表格
                reloadChannelTable();
            };

            // 格式化日期时间
            function formatDate(date) {
                const year = date.getFullYear();
                const month = String(date.getMonth() + 1).padStart(2, '0');
                const day = String(date.getDate()).padStart(2, '0');
                const hours = String(date.getHours()).padStart(2, '0');
                const minutes = String(date.getMinutes()).padStart(2, '0');
                const seconds = String(date.getSeconds()).padStart(2, '0');
                return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
            }

            // 重新加载文章表格数据
            function reloadArticleTable() {
                table.reload('article-table', {
                    where: {
                        date: articleDate
                    },
                });
            }

            // 重新加载栏目表格数据
            function reloadChannelTable() {
                table.reload('channel-table', {
                    where: {
                        date: channelDate
                    },
                });
            }

            /**
             * 获取总访问数量
             */
            fetch(baseURL + 'visitCount/total-visit-count')
                .then(response => response.json())
                .then(data => {
                    if (data.code === 1000) {
                        count.up("ipVisitCount", {
                            time: 4000,
                            num: data.data,
                            bit: 0,
                            regulator: 50
                        });
                    } else {
                        console.error('查询访问总数失败', data.msg);
                    }
                })
                .catch(error => console.error('异常处理:', error));
            /**
             *获取信息流量总数
             */
            fetch(baseURL + 'cms/infoArticle/totalViewCount')
                .then(response => response.json())
                .then(data => {
                    if (data.code === 1000) {
                        count.up("infoValue", {
                            time: 4000,
                            num: data.data,
                            bit: 0,
                            regulator: 50
                        });
                    } else {
                        console.error('查询信息流量总数失败', data.msg);
                    }
                })
                .catch(error => console.error('异常处理:', error));
            /**
             *获取栏目流量总数
             */
            fetch(baseURL + 'cms/channel/getTotalCount')
                .then(response => response.json())
                .then(data => {
                    if (data.code === 1000) {
                        count.up("channelValue", {
                            time: 4000,
                            num: data.data,
                            bit: 0,
                            regulator: 50
                        });
                    } else {
                        console.error('查询栏目流量总数失败', data.msg);
                    }
                })
                .catch(error => console.error('异常处理:', error));

            /**
             * 获取每日访问量
             */
            //获取当前用户名
            fetch(baseURL + 'user/getCurrentUsername')
                .then(response => response.json())
                .then(data => {
                    if (data.code === 1000) {
                        const username = data.data;
                        document.getElementById('welcome-message').innerText = `欢迎你，${username}！`;
                    } else {
                        console.error('获取用户名失败', data.msg);
                    }
                })
                .catch(error => console.error('异常处理:', error));

            // 获取版权信息
            fetch(baseURL + 'setting/copyright')
                .then(response => response.json())
                .then(data => {
                    if (data.webCopyright) {
                        const copyrightElement = document.createElement('div');
                        copyrightElement.className = 'copyright-info';
                        copyrightElement.innerText = data.webCopyright;
                        document.body.appendChild(copyrightElement);
                    } else {
                        console.error('获取版权信息失败', data);
                    }
                })
                .catch(error => console.error('异常处理:', error));
        });


    });

    function triggerExport() {
        // 添加时间戳防止缓存
        const exportLink = document.getElementById("exportChannel");
        exportLink.href = baseURL + `cms/channel/export?t=${Date.now()}`;

        // 触发点击事件
        exportLink.click();

        // 可选：显示导出提示
        alert("导出已开始，请稍候...");
    }
</script>
</body>

<style>
    .welcome-message {
        font-family: 'Poppins', sans-serif; /* 使用Roboto字体 */
        font-size: 30px;
        text-align: center;
        color: rgba(40, 51, 62, 0.8); /* 设置字体颜色为RGBA(40, 51, 62, 0.8)，透明度为0.8 */
        -webkit-background-clip: text;
        text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3); /* 文本阴影 */
        padding: 10px; /* 内边距 */
        position: relative; /* 相对定位 */
        overflow: hidden; /* 隐藏溢出内容 */
        z-index: 1; /* 设置z-index */
        animation: fadeIn 2s ease-in-out, gradientAnimation 5s infinite alternate; /* 动画效果 */
        display: flex; /* 使用flex布局 */
        align-items: center; /* 垂直居中 */
        justify-content: center; /* 水平居中 */
        height: 100%; /* 确保高度占满父元素 */
    }

    /* 定义淡入动画 */
    @keyframes fadeIn {
        from {
            opacity: 0;
        }
        to {
            opacity: 1;
        }
    }

    .copyright-info {
        text-align: center;
        padding: 10px;
        background-color: #f8f9fa;
        border-top: 1px solid #e9ecef;
        position: fixed;
        bottom: 0;
        width: 100%;
    }
</style>

</html>

